package main.Q901_1000;

public class Q951_960 {
    public static void main(String[] args) {
        System.out.println("Question951：");
        System.out.println("Question952：");
        System.out.println("Question953：验证外星词典");
        System.out.println("Question954：");
        System.out.println("Question955：");
        System.out.println("Question956：");
        System.out.println("Question957：");
        System.out.println("Question958：");
        System.out.println("Question959：");
        System.out.println("Question960：");
    }
}

class Question953{
    public boolean isAlienSorted(String[] words, String order) {
        for (int i = 0; i < words.length - 1; i++) {
            int n = words[i].length(), m = words[i + 1].length(),min = n < m ? n : m,j = 0;
            for (; j < min; j++) {
                // 判断是否满足第 1，2 种情况
                if (order.indexOf(words[i].charAt(j)) > order.indexOf(words[i + 1].charAt(j))) {
                    return false;
                }
                if (order.indexOf(words[i].charAt(j)) < order.indexOf(words[i + 1].charAt(j))) {
                    break;
                }
            }
            // 判断是否满足第 3 种情况
            if (j == min && n > m) {
                return false;
            }
        }
        return true;
    }
}